package com.gree.flowable.configurations;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
//@Profile("dev")
public class Swagger2Config {
    /**
     * @return
     * @Title: 配置了 Swagger的Docket的bean实例
     * @Description: Docket实现了 DocumentationPlugin插件接口
     */
    @Bean
    public Docket docket(Environment environment) {

        // 获取项目的环境：
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(this.apiInfo())
                .enable(true)
                .select()
                // RequestHandlerSelectors，配置要扫描接口的方式
                // basePackage（） 指定要扫描的包 any():扫描全部 none(): 不扫描
                // withClassAnnotation：扫描类上的注解
                .apis(RequestHandlerSelectors.basePackage("com.gree.flowable.app.controller"))
                // paths(). 过滤什么路径
//                .paths(PathSelectors.ant("/kuang/**"))
                .build();
    }

    // 配置Swagger信息=apiInfo 帮助文档信息
    private ApiInfo apiInfo() {
        // 作者信息
        Contact contact = new Contact("李炳乾","https://github.com/afterToday1","180681@it2004.gree.com.cn");
        return new ApiInfo("flowable API文档",
                "再小的帆也能远航",
                "v1.0",
                "https://blog.kuangstudy.com/", contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
